home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / Frame1.java < prev    next >
Text File  |  1998-10-30  |  2KB  |  103 lines

  1. /*
  2.     A basic extension of the java.awt.Frame class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class Frame1 extends Frame
  8. {
  9.     public Frame1()
  10.     {
  11.         // This code is automatically generated by Visual Cafe when you add
  12.         // components to the visual environment. It instantiates and initializes
  13.         // the components. To modify the code, only use code syntax that matches
  14.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  15.         // parse your Java file into its visual environment.
  16.         //{{INIT_CONTROLS
  17.         setLayout(null);
  18.         setSize(400,300);
  19.         setTitle("A Simple Frame");
  20.         //}}
  21.  
  22.         //{{INIT_MENUS
  23.         //}}
  24.  
  25.         //{{REGISTER_LISTENERS
  26.         SymWindow aSymWindow = new SymWindow();
  27.         this.addWindowListener(aSymWindow);
  28.         //}}
  29.     }
  30.  
  31.     public Frame1(String title)
  32.     {
  33.         this();
  34.         setTitle(title);
  35.     }
  36.  
  37.     /**
  38.      * Shows or hides the component depending on the boolean flag b.
  39.      * @param b  if true, show the component; otherwise, hide the component.
  40.      * @see java.awt.Component#isVisible
  41.      */
  42.     public void setVisible(boolean b)
  43.     {
  44.         if(b)
  45.         {
  46.             setLocation(50, 50);
  47.         }
  48.         super.setVisible(b);
  49.     }
  50.  
  51.     static public void main(String args[])
  52.     {
  53.         (new Frame1()).setVisible(true);
  54.     }
  55.     
  56.     public void addNotify()
  57.     {
  58.         // Record the size of the window prior to calling parents addNotify.
  59.         Dimension d = getSize();
  60.         
  61.         super.addNotify();
  62.  
  63.         if (fComponentsAdjusted)
  64.             return;
  65.  
  66.         // Adjust components according to the insets
  67.         Insets insets = getInsets();
  68.         setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
  69.         Component components[] = getComponents();
  70.         for (int i = 0; i < components.length; i++)
  71.         {
  72.             Point p = components[i].getLocation();
  73.             p.translate(insets.left, insets.top);
  74.             components[i].setLocation(p);
  75.         }
  76.         fComponentsAdjusted = true;
  77.     }
  78.  
  79.     // Used for addNotify check.
  80.     boolean fComponentsAdjusted = false;
  81.  
  82.     //{{DECLARE_CONTROLS
  83.     //}}
  84.  
  85.     //{{DECLARE_MENUS
  86.     //}}
  87.  
  88.     class SymWindow extends java.awt.event.WindowAdapter
  89.     {
  90.         public void windowClosing(java.awt.event.WindowEvent event)
  91.         {
  92.             Object object = event.getSource();
  93.             if (object == Frame1.this)
  94.                 Frame1_WindowClosing(event);
  95.         }
  96.     }
  97.     
  98.     void Frame1_WindowClosing(java.awt.event.WindowEvent event)
  99.     {
  100.         setVisible(false);         // hide the Frame
  101.     }
  102. }
  103.